home *** CD-ROM | disk | FTP | other *** search
/ Singles Flirt Up Your Life! (German) / Singles Flirt Up Your Life.iso / data1.cab / Statemachine / sinkToilet.lua < prev    next >
Text File  |  2004-01-29  |  4KB  |  122 lines

  1. -- sink state machine
  2.  
  3. beginStateMachine()
  4.  
  5.     onMsg("buildMenu", function(msg)
  6.     
  7.         if (repairMenu()) then return end
  8.     
  9.         -- build the pie menu
  10.         clearPieMenu();
  11.         button = addPieMenuButton("pm_washHands", "washHands");
  12.         button.addDescription(ACTIVITY, "washHands");
  13.         button = addPieMenuButton("pm_brushTeeth", "brushTeeth");
  14.         button.addDescription(ACTIVITY, "brushTeeth");
  15.         button = addPieMenuButton("pm_makeHair", "makeHair");
  16.         button.addDescription(ACTIVITY, "makeHair");
  17.         -- button.addIcon("guiIconHygiene");
  18.     end )
  19.  
  20.     -- 
  21.     onMsg("washHands", function(msg)
  22.         -- get the game object server
  23.         local gameObjectServer = getGameObjectServer();
  24.         -- get character who initiated this action
  25.         local character = getStateObjectFromID(msg.sender);
  26.         -- walk to the closest action point
  27.         local actionPoint = character.getFreeActionPoint(this, "washHands");
  28.         if (actionPoint) then
  29.             -- notify current mission 
  30.             character.sendMsg("washHands", gameObjectServer.mission);
  31.             
  32.             -- get the walk state object
  33.             local wso = character.walkSO;
  34.             if (wso.walkToActionPoint(actionPoint)) then
  35.                 wso.queueStateMachine("sinkChar.washHandsStart", this);
  36.             else
  37.                 print("no path found");
  38.                 instantAbort(character, EMOTICON_NOPATH, "emoThink")
  39.             end
  40.         else
  41.             print("no action point found");
  42.             instantAbort(character, EMOTICON_CANNOT, "emoThink")
  43.         end
  44.     end )
  45.             
  46.     onMsg("brushTeeth", function(msg)
  47.         -- get the game object server
  48.         local gameObjectServer = getGameObjectServer();
  49.         -- get character who initiated this action
  50.         local character = getStateObjectFromID(msg.sender);
  51.         -- walk to the closest action point
  52.         local actionPoint = character.getFreeActionPoint(this, "washHands");
  53.         if (actionPoint) then
  54.             -- get the walk state object
  55.             local wso = character.walkSO;
  56.             if (wso.walkToActionPoint(actionPoint)) then
  57.                 wso.queueStateMachine("sinkChar.brushTeethStart", this);
  58.             else
  59.                 print("no path found");
  60.                 instantAbort(character, EMOTICON_NOPATH, "emoThink")
  61.             end
  62.         else
  63.             print("no action point found");
  64.             instantAbort(character, EMOTICON_CANNOT, "emoThink")
  65.         end
  66.     end )
  67.     
  68.     
  69.     onMsg("makeHair", function(msg)
  70.         -- get the game object server
  71.         local gameObjectServer = getGameObjectServer();
  72.         -- get character who initiated this action
  73.         local character = getStateObjectFromID(msg.sender);
  74.         -- walk to the closest action point
  75.         local actionPoint = character.getFreeActionPoint(this, "washHands");
  76.         if (actionPoint) then
  77.             -- get the walk state object
  78.             local wso = character.walkSO;
  79.             if (wso.walkToActionPoint(actionPoint)) then
  80.                 wso.queueStateMachine("sinkChar.makeHair", this);
  81.             else
  82.                 print("no path found");
  83.                 instantAbort(character, EMOTICON_NOPATH, "emoThink")
  84.             end
  85.         else
  86.             print("no action point found");
  87.             instantAbort(character, EMOTICON_CANNOT, "emoThink")
  88.         end
  89.     end )
  90.     
  91.     
  92.     -- repair
  93.     onMsg("repair", function(msg)
  94.     
  95.         print("onMsg repair");
  96.         -- get character who initiated this action
  97.         local character = getStateObjectFromID(msg.sender);
  98.         -- walk to the closest action point
  99.         local actionPoint = character.getFreeActionPoint(this, "repair");
  100.         -- get the walk state object
  101.         local wso = character.walkSO;
  102.         if (actionPoint) then
  103.             -- create state machine contexts
  104.             local wsoContext = StateMachineContext();
  105.             -- store the action point
  106.             wsoContext.storeData("actionPointName", actionPoint.getName());
  107.             if (wso.walkToActionPoint(actionPoint)) then
  108.                 wso.queueStateMachine("repairChar.repairStart", this, wsoContext);
  109.             else
  110.                 print("no path found");
  111.                 instantAbort(character, EMOTICON_NOPATH, "emoThink")
  112.             end
  113.         else
  114.             print("no action point found");
  115.             instantAbort(character, EMOTICON_CANNOT, "emoThink")
  116.         end
  117.     end )
  118.     
  119.     
  120.             
  121. endStateMachine()
  122.